package biz

import (
	"context"
	"golang.org/x/sync/errgroup"
)

type OwnerInfo interface {
	GetOwner(string) string
}
type PathInfo interface {
	GetPath(string) string
}

type InfoData struct {
	Path      string
	Owner     string
	ServiceID string
}

type Info struct {
	o OwnerInfo
	p PathInfo
}

func NewInfo() *Info {
	return &Info{}
}

func (i *Info) GetInfo(ctx context.Context, instance string) (InfoData, error) {
	eg, _ := errgroup.WithContext(ctx)
	var (
		owner = ""
		path  = ""
	)
	eg.Go(func() error {
		owner = i.o.GetOwner(instance)
		return nil
	})
	eg.Go(func() error {
		path = i.p.GetPath(instance)
		return nil
	})
	if err := eg.Wait(); err != nil {
		return InfoData{}, err
	}
	return InfoData{
		Path:      path,
		Owner:     owner,
		ServiceID: instance,
	}, nil
}
